package com.yeung.exam;

import java.util.Scanner;

public class Base64编码实现 {
//    Character[] code = {'A', 'B', 'C', 'D', 'E'}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        StringBuilder sb = new StringBuilder();
        for (char c : line.toCharArray()) {
            int cv = (int) c;
            String binaryStr = Integer.toBinaryString(cv);
            sb.append(binaryStr);
        }
        //平成了一串二进制
        //没6位解析一次
        StringBuilder newStr = new StringBuilder();
        StringBuffer nsb = new StringBuffer();

        int groups = (int) Math.ceil(sb.length() / 6.0);
        for (int group = 0; group < groups; group++) {
            char[] part = new char[6];
            for (int i = 0; i < part.length; i++) {
                part[i] = '0';//初始化值
            }
            int start = group * 6;
            int end = (start + 6 <= sb.length()) ? start + 6 : sb.length();
            sb.getChars(start, end, part, 0);
            int value = getValue(part);
            char newCode = toChar(value);
            newStr.append(newCode);
        }
        System.out.println(newStr.toString());

    }

    public static int getValue(char[] code) {
        int sum = 0;
        for (int i = 0; i < code.length; i++) {
            int sn = Integer.parseInt(code[i] + "");
            sum += Math.pow(2, (5 - i)) * sn;
        }
        return sum;
    }

    public static char toChar(int value) {
        char[] code = {
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
                'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
                'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
        return code[value];
    }
}

